const apiKey = 'sk-8ddd957a198f4fd79b88a9e66d7a951d'

import OpenAI from "openai";

try {
  const openai = new OpenAI(
    {
      // 若没有配置环境变量，请用百炼API Key将下行替换为：apiKey: "sk-xxx",
      apiKey,
      baseURL: "https://dashscope.aliyuncs.com/compatible-mode/v1"
    }
  );
  const completion = await openai.chat.completions.create({
    model: "qwen-plus",
    messages: [
      { role: "system", content: "You are a helpful assistant." },
      { role: "user", content: "你是谁？" }
    ],
  });
  console.log(completion.choices[0].message.content);
} catch (error) {
  console.log(`错误信息：${error}`);
  console.log("请参考文档：https://help.aliyun.com/zh/model-studio/developer-reference/error-code");
}
